<template>
  <div>
    <!-- 常见问题 2018/4/11 18:46 zuoW -->
    <!-- content -->
    <div style="background-color: #13293B;transition: all 1s ease-in;margin-top: -60px;height: 60px;"></div>
    <div style="height: 100%; background: #fff;margin-top: 50px; margin-bottom: 50px;">
      <div style="width: 960px; margin:0 auto; background: #fff;">
        <div class="content">
          <div class="content_title">
            <h5>常见问题</h5>
          </div>
          <div class="problemContent">
            <div class="problemMenu">
              <ul class="problemMenuFristDegreeUl">
                <li class="problemMenuFristDegreeLi">
                  <div class="problemMenuFristDegreeTitle"><h6>{{ newList4Title }}</h6></div>
                  <ul class="problemMenuSecondDegreeUl">
                    <li class="problemMenuSecondDegreeLi" v-for="(item,i) in newList4"
                        @click="showContentAction(item,i,newList='newList4')"><a href="javascript:void(0)"
                                                                                 :class="activeStyle=='newList4'+i?'active':''">{{
                      item.title }}</a></li>
                  </ul>
                </li>
                <li class="problemMenuFristDegreeLi">
                  <div class="problemMenuFristDegreeTitle"><h6>{{ newList5Title }}</h6></div>
                  <ul class="problemMenuSecondDegreeUl">
                    <li class="problemMenuSecondDegreeLi" v-for="(item,i) in newList5"
                        @click="showContentAction(item,i,newList='newList5')"><a href="javascript:void(0)"
                                                                                 :class="activeStyle=='newList5'+i?'active':''">{{
                      item.title }}</a></li>
                  </ul>
                </li>
              </ul>
            </div>
            <div class="problemC">
              <div class="problemSearch">
                <Form>
                  <FormItem>
                    <Input placeholder="输入搜索内容" style="width: 350px;height: 36px;" v-model="keywords"></Input>
                    <Button icon="ios-search" class="trackCodeSraechBtn"
                            style="width: 100px;height: 36px;font-size: 14px;" @click="searchKeyWord(keywords)">搜索
                    </Button>
                    <div class="hotSearch">热门搜索：
                      <a href="javascript:void(0)" @click="searchKeyWord(keywords='注册')">注册</a>|
                      <a href="javascript:void(0)" @click="searchKeyWord(keywords='营业执照上传')">营业执照上传</a>|
                      <a href="javascript:void(0)" @click="searchKeyWord(keywords='审核')">审核</a>|
                      <a href="javascript:void(0)" @click="searchKeyWord(keywords='更改密码')">更改密码</a>|
                      <a href="javascript:void(0)" @click="searchKeyWord(keywords='App怎么下载')">App怎么下载</a>
                    </div>
                  </FormItem>
                </Form>
              </div>
              <div class="problemArticle" v-html="showContent" v-if="noSearch">
              </div>
              <div class="problemArticle" v-if="!noSearch">
                <div class="searchResultList" v-if="hassearchResult==1">
                  <ul>
                    <li v-for="(item,i) in searchList" @click="showContentAction(item,i,newList='search')">
                      <a href="javascript:void(0)">
                        <h5 v-html="item.artTitle"></h5>
                        <div v-html="item.artContent"></div>
                      </a>
                    </li>
                  </ul>
                </div>
                <div class="nosearchResult" v-if="hassearchResult==2">
                  <h4><span style="color:#EB1010">&nbsp;&nbsp;!&nbsp;&nbsp;</span>对不起，没有找到“{{keywords}}“相关的信息</h4>
                  <div class="noResultSuggest">
                    <p>建议：</p>
                    <p style="margin-left: 35px;">请检查输入字词是否有误</p>
                    <p style="margin-left: 35px;">请尝试其他搜索词</p>
                    <p style="margin-left: 35px;">拨打联运e达服务热线&nbsp;&nbsp;18963800909 </p>
                  </div>
                </div>
              </div>
            </div>
            <div style="clear: both"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import {getAllList} from '@api/frontEnd'
  /* import moment from 'moment' */

  export default {
    name: 'problem',
    data () {
      let trackingCodeForm = {
        orderNo: ''
      }
      let keywords = ''
      let activeStyle = ''
      let searchList = []
      let noSearch = true
      let newList4 = []
      let newList5 = []
      let newList4Title = ''
      let newList5Title = ''
      let showContent = ''
      let hassearchResult = 0
      let newList4Param = {
        'page': 1,
        'pageSize': 10000,
        'typeId': '4',
        'like': ''
      }
      let newList5Param = {
        'page': 1,
        'pageSize': 10000,
        'typeId': '5',
        'like': ''
      }
      let datas = {
        trackingCodeForm,
        newList4,
        newList5,
        newList4Param,
        newList5Param,
        newList4Title,
        newList5Title,
        activeStyle,
        showContent,
        keywords,
        noSearch,
        searchList,
        hassearchResult
      }
      return datas
    },
    methods: {
      loadNewList () {
        getAllList(this.newList4Param).then(res => {
          if (res.data.isSuccess === 1) {
            this.newList4 = res.data.data.reverse()
            this.newList4Title = this.newList4[0].type_name
          }
          getAllList(this.newList5Param).then(res => {
            let thisnewList = this.$route.query.name
            if (res.data.isSuccess === 1) {
              this.newList5 = res.data.data.reverse()
              this.newList5Title = this.newList5[0].type_name
            }
            if (thisnewList === '1') {
              this.activeStyle = 'newList40'
              this.showContent = this.newList4[0].content
            } else if (thisnewList === '2') {
              this.activeStyle = 'newList50'
              this.showContent = this.newList5[0].content
            }
          })
        })
      },
      showContentAction (item, i, newList) {
        this.noSearch = true
        this.showContent = item.content
        this.activeStyle = newList + i
      },
      searchKeyWord (keyword) {
        if (this.keywords) {
          this.activeStyle = 'search'
          this.hassearchResult = 3
          let param = {
            'page': 1,
            'pageSize': 10000,
            'typeId': '4,5',
            'like': this.keywords
          }
          getAllList(param).then(res => {
            let searchList = []
            this.noSearch = false
            if (res.data.isSuccess === 1) {
              let dataList = res.data.data
              let keyWordReg = new RegExp(this.keywords, 'g')
              let replaceWord = '<span style="color:#EB1010">' + this.keywords + '</span>'
              if (dataList.length > 0) {
                this.hassearchResult = 1
                dataList.forEach((item) => {
                  let words = item.content.replace(/<\/?.+?>/g, '').replace(/ /g, '').replace(/\s+/g, '')
                  let artContent = words.replace(keyWordReg, replaceWord)
                  let artTitle = item.title.replace(keyWordReg, replaceWord)
                  let thisArt = Object.assign({}, {
                    'artContent': artContent,
                    'artTitle': artTitle,
                    'content': item.content
                  })
                  searchList.push(thisArt)
                })
                this.searchList = searchList
              } else {
                this.hassearchResult = 2
                this.searchList = []
              }
            }
          })
        }
      }
    },
    mounted () {
      this.loadNewList()
    },
    watch: {
      keywords: {
        handler: function (val, oldVal) {
          if (val !== oldVal) {
            this.hassearchResult = 3
          }
        }
      }
    }
  }
</script>

<style scoped="scoped">
  .h5, h5 {
    font-size: 1.25rem;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.1;
    color: inherit;
  }

  .footers > div {
    /*float: left;*/
    font-size: 14px;
  }

  .footers > div > p {
    font-size: 18px;
    color: #FDFDFD;
    border-left: 1px solid #1B364D;
    padding-left: 15px;
  }

  .footers > .foo4 > p {
    font-size: 14px;
    color: #CACACA;
    margin-top: 3px;
  }

  .footers > .foo4 > img {
    display: inline-block;
    width: 96px;
    height: 88px;
    border-left: 1px solid #1B364D;
    padding-left: 15px;
    padding-top: 8px;
  }

  .footers > .foo4 > p:first-of-type {
    font-size: 18px;
    color: #FDFDFD;
  }

  .footers > div > p > a {
    text-decoration: none;
    font-size: 14px;
    color: #CACACA;
  }

  #mianDeng > p:first-of-type {
    margin-top: 30px;
    font-size: 22px;
    color: #1B1E21;
  }

  #mianDeng > p:last-of-type {
    width: 120px;
    height: 40px;
    margin: 0 auto;
    margin-top: 30px;
    background-color: #1B1E21;
    line-height: 40px;
  }

  #mianDeng a {
    text-decoration: none;
    color: #FECA2E;
    font-size: 16px;
  }

  .content {
    margin-top: 40px;
    background: #fff;
  }

  .content_main {
    margin-top: 40px;
    font-size: 16px;
  }

  p {
    line-height: 30px;
  }

  .content_title h5 {
    font-size: 24px;
    color: #333333;
    line-height: 42px;
  }

  .problemContent {
    width: 100%;
  }

  .problemMenu {
    float: left;
    width: 30%;
  }

  .problemC {
    float: left;
    width: 70%;
    padding: 0 30px;
    min-height: 760px;
    border-left: 1px solid #DFDFDF;;
  }

  .problemMenu ul, .problemMenu li {
    list-style: none;
    width: 287px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .problemMenuFristDegreeTitle {
    margin: 24px 0 10px 0;
  }

  .problemMenuFristDegreeTitle h6 {
    font-size: 18px;
    color: #333333;
    line-height: 28px;
    font-weight: normal;
  }

  .problemMenuSecondDegreeLi {
    font-size: 14px;
    line-height: 35px;
  }

  .problemMenuSecondDegreeLi a {
    color: #aaa;
  }

  .problemMenuSecondDegreeUl .active {
    color: #333333;
  }

  .problemSearch {

  }

  .trackCodeSraechBtn {
    margin-left: 10px;
    padding: 5px 15px;
    background-color: #FECA2E;
    border-color: #FFDB59;
  }

  .trackCodeSraechBtn:hover {
    color: #495060;
  }

  .problemArticle {
  }

  .hotSearch {
    font-size: 14px;
    color: #aaa;
    line-height: 30px;
    height: 30px;
  }

  .hotSearch a {
    margin: 0 5px;
    color: #aaa;
  }

  .hotSearch a:hover {
    color: #333;
  }

  .searchResultList ul {
    list-style: none;
  }

  .searchResultList ul li {
    list-style: none;
    width: 100%;
    padding: 10px 0;
    border-bottom: 1px dashed #E9E9E9;
  }

  .searchResultList ul li h5 {
    font-size: 20px;
    color: #333333;
    line-height: 30px;
  }

  .searchResultList ul li div {
    font-size: 14px;
    width: 100%;
    color: #333333;
    line-height: 20px;
    max-height: 40px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  .nosearchResult {
    margin-top: 40px;
  }

  .nosearchResult h4 {
    font-size: 20px;
    color: #000000;
  }

  .nosearchResult .noResultSuggest {
    font-size: 14px;
    color: #333333;
    margin-top: 20px;
  }

  .nosearchResult .noResultSuggest p {
    line-height: 30px;
    margin-left: 10px;
  }
</style>
<style>
  .ivu-layout {
    background-color: #fff;
  }
</style>
